/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bsu.cs342.lab1.cache;

import java.lang.*;
import java.io.*;
import java.util.*;
import java.util.LinkedList;

/**
 *
 * @author Sam Jenkins
 */
public class Cache
        extends LinkedList<Object> {

    private int maxCacheSize;
    private int currentCacheSize = 0;

    public void Cache(int cacheSize) {
        this.maxCacheSize = cacheSize;

    }

    public boolean containsObject(Object object) {
        Iterator itr = this.iterator();
        while (itr.hasNext()) {
            Object currentObject = itr.next();
            if (object.equals(currentObject)) {
                return true;
            }
        }
        return false;
    }
//    public Object getObject(Object object){
//        this.
//        
//        return this.getObject();
//    }
    public void addObject(Object object) {
        if (currentCacheSize >=  maxCacheSize) {
            this.removeLast();
        }else{
            this.currentCacheSize++;
        }
        this.push(object);
    }

    public void removeObject(Object object) {
        Iterator itr = this.iterator();
        while (itr.hasNext()) {
            Object currentObject = itr.next();
            if (object.equals(currentObject)) {
                itr.remove();
            }
        }
    }

    public void clearCache() {
        this.clear();
    }
}
